package com.yanqu.road.entity.activity.yuanbaolottery;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.config.system.NormalWeightItem;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_s_activity_yuanbao_lottery")
public class YuanBaoLotteryConfig {
    @FieldTypeAnnotation(select = true, isIndex = true)
    private int activityId;
    @FieldTypeAnnotation(desc = "id", isIndex = true)
    private int id;
    @FieldTypeAnnotation(desc = "道具消耗数量")
    private int consume;
    @FieldTypeAnnotation(desc = "元宝需求数量")
    private int needNum;
    @FieldTypeAnnotation(desc = "倍率参数")
    private String param;

    private List<NormalWeightItem> weightList = new ArrayList<>();

    public YuanBaoLotteryConfig(ResultSet rs) throws SQLException {
        this.activityId = rs.getInt("activityId");
        this.id = rs.getInt("id");
        this.consume = rs.getInt("consume");
        this.needNum = rs.getInt("needNum");
        this.param = rs.getString("param");

        if (!StringUtils.isNullOrEmpty(param)) {
            List<NormalWeightItem> tempList = new ArrayList<>();
            String[] params = param.split("\\|");
            for (int i = 0; i < params.length; i++) {
                int pos = i;
                tempList.add(new YuanBaoLotteryWeight(pos, params[i]));
            }
            weightList = tempList;
        }
    }

    public int getActivityId() {
        return activityId;
    }

    public int getId() {
        return id;
    }

    public int getConsume() {
        return consume;
    }

    public int getNeedNum() {
        return needNum;
    }

    public String getParam() {
        return param;
    }

    public List<NormalWeightItem> getWeightList() {
        return weightList;
    }
}
